package vaani.swar.grammar;

import edu.cmu.sphinx.jsapi.JSGFGrammar;
import edu.cmu.sphinx.util.props.ConfigurationManager;
import java.net.URL;
import javax.speech.recognition.GrammarException;
import javax.speech.recognition.Rule;
import javax.speech.recognition.RuleGrammar;

/**
 *
 * @author sourcemorph
 */

/*class for all grammar constructor classes to extend*/

public abstract class GenericGrammarConstructor {
    
    protected static JSGFGrammar jsgfGrammarManager;

    static {
        //URL url = InstantMessageGrammarConstructor.class.getResource("jsgf.config.xml");
        URL url = Thread.currentThread().getContextClassLoader().getResource("data/jsgf.config.xml");
        ConfigurationManager cm = new ConfigurationManager(url);
        jsgfGrammarManager = (JSGFGrammar) cm.lookup("jsgfGrammar");
    }

    protected static void addRule(RuleGrammar ruleGrammar, String ruleName, String jsgf) throws GrammarException {
        Rule rule = ruleGrammar.ruleForJSGF(jsgf);
        ruleGrammar.setRule(ruleName, rule, true);
        ruleGrammar.setEnabled(ruleName, true);
    }
}
